//导入 express
const express = require('express');
const singers = require('./singer.json');
const fs = require('fs');
const ejs = require('ejs');
//创建应用对象
const app = express();
//
app.use(express.static('./public'));

//创建路由规则
app.get('/singers', (req, res) => {
  //获取歌手数据
  let content = fs.readFileSync('./views/singers.ejs').toString();
  let html = ejs.render(content, {singers})
  res.send(html);
});

//监听端口 启动服务
app.listen(8080, () =>{
  console.log('waiting for connection on port 8080...');
});